<div class="layui-fluid" lay-title="表单组合">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">表名</label>
                    <div class="layui-input-block">
                        <input type="text" name="tableName" disabled lay-verify="required" autocomplete="off" placeholder="请输入表名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">模块</label>
                    <div class="layui-input-block">
                        <input type="text" name="moduleName" lay-verify="required" autocomplete="off" placeholder="请输入模块名" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">类名</label>
                    <div class="layui-input-block">
                        <input type="text" name="className" lay-verify="required" autocomplete="off" placeholder="请输入类名" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">作者</label>
                    <div class="layui-input-block">
                        <input type="text" name="author" lay-verify="required" autocomplete="off" placeholder="请输入作者" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">包名</label>
                    <div class="layui-input-block">
                        <input type="text" name="packageInfo" lay-verify="required" autocomplete="off" placeholder="请输入包名" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">输出文件夹</label>
                    <div class="layui-input-block">
                        <input type="text" name="outputDir" lay-verify="required" autocomplete="off" placeholder="请输入输出文件夹" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="form-group-submit">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    layui.use(['jquery', 'admin', 'form','layer'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , admin = layui.admin;
        var tableName = POPUP_DATA.tableName;
        var table = POPUP_DATA.table;
        form.render(null, 'form-group');
        var tableInfo = {};
        // 初始化
        admin.get({
            type: 'get',
            url: '/gen/getTableByName/' + tableName,
            dataType: 'json',
            success: function (data) {
                tableInfo = data.tableInfo;
                if (tableInfo) {
                    form.val("form-group", {
                        "tableName": tableInfo.tableName // "name": "value"
                        , "className": tableInfo.className
                        , "moduleName": tableInfo.moduleName
                        , "outputDir": tableInfo.outputDir
                        , "author" : tableInfo.author
                        , "packageInfo" : tableInfo.packageInfo
                    });
                }
            }
        });

        form.on('submit(form-group-submit)', function (data) {
            var field = data.field;
            var tableData = {};
            tableData.tableName = field.tableName;
            tableData.className = field.className;
            tableData.moduleName = field.moduleName;
            tableData.outputDir = field.outputDir;
            tableData.author = field.author;
            tableData.packageInfo = field.packageInfo;
            admin.post({
                url: "/gen/generate",
                contentType: "application/json",
                data: JSON.stringify(tableData),
                success: function (res) {
                    if (res.code == 0) {
                        // 提醒保存成功，关闭当前弹窗
                        layer.msg(res.msg);
                        layer.closeAll();
                        //刷新
                        //treeGrid.reload("treeTable");
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>